package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/
 * @create 2025/9/10 10:15
 * @since JDK17
 */

public class Solution08 {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode newList = new ListNode(), p = newList, pre;
        while (head != null) {
            pre = head;
            while (head != null && head.next != null) {
                if (head.val != head.next.val) {
                    break;
                }
                pre = head;
                head = head.next;
            }
            if (pre == head) {
                p = p.next = head;
            }
            head = head.next;
        }
        p.next = null;
        return newList.next;
    }
}
